package com.yiduo.outpost.core.web.exception;

import com.yiduo.outpost.core.model.exception.ErrorConstants;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.net.ConnectException;

/**
 * @author yanwen
 */
public class ConnectExceptionTranslator implements ExceptionTranslator {

    @Override
    public boolean support(Throwable error) {
        return error != null && error.getCause() instanceof ConnectException;
    }

    @Override
    public String translateException(Throwable error, MessageSource messageSource) {
        return messageSource.getMessage(ErrorConstants.ERROR_TIMEOUT, null, LocaleContextHolder.getLocale());
    }
}
